import axios from 'axios'

const api = axios.create({
    baseURL: 'http://localhost:5000',
    timeout: 10000
})

export default {
    // 车辆入库
    vehicleIn(file) {
        const formData = new FormData()
        formData.append('file', file)
        return api.post('/detect/in', formData)
    },

    // 车辆出库
    vehicleOut(file) {
        const formData = new FormData()
        formData.append('file', file)
        return api.post('/detect/out', formData)
    },

    // 查询记录
    getRecords(params) {
        return api.get('/detect/records', {params})
    },

    // 时段统计接口
    getHourlyStats(params) {
        return api.get('/stats/hourly', {
            params: {
                start_time: params.start,
                end_time: params.end
            }
        }).then(res => res.data) // 确保返回的是数据数组
    },

    // 场内车辆数据接口
    getCurrentStatus() {
        return api.get('/stats/current').then(res => res.data)
    },
    // 导出记录
    exportRecords: (params) => api.get('/records/export', {
        params,
        responseType: 'blob',
        headers: {
            'Cache-Control': 'no-cache',
            'Pragma': 'no-cache'
        }
    }),
    // 热力图数据接口
    getHeatmapData(params) {
        return api.get('/stats/heatmap', {params})
    },
    // 营收分析接口
    getRevenueAnalysis(params) {
        return api.get('/stats/revenue', {
            params: {
                granularity: params.granularity
            }
        })
    }


}